package service;
/**
 * 注册中心
 * */

import serviceDefine.BookService;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class ServiceRegister {
    public static void main(String[] args) throws Exception{
        String serverIP = "192.168.232.140";
        System.setProperty("java.rmi.server.hostname", serverIP);
       try {
           String name = "BookManager";//服务的名字
           BookService engine = new BookServiceImpl();
           BookService skeleton = (BookService)UnicastRemoteObject.exportObject(engine, 0);//port为0表明使用匿名随机端口
           //本地主机上的远程对象注册表Registry的实例，这一步必不可少（Java默认端口是1099）
           LocateRegistry.createRegistry(1099);
           Registry registry = LocateRegistry.getRegistry("127.0.0.1",1099);
           System.out.println("service is online");
           registry.rebind(name, skeleton);
       }catch (Exception e){
           e.printStackTrace();
       }
    }
}
